package com.sinven.controller;

import com.sinven.common.ActionResult;
import com.sinven.pojo.Article;
import com.sinven.pojo.Environment;
import com.sinven.pojo.Student;
import com.sinven.pojo.Teacher;
import com.sinven.service.ArticleService;
import com.sinven.service.EnvService;
import com.sinven.service.StudentService;
import com.sinven.service.TeacherService;
import com.sinven.vo.ArticleCondition;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
public class IndexController {

    @Autowired
    private ArticleService articleService;
    @Autowired
    private EnvService envService;
    @Autowired
    private TeacherService teacherService;
    @Autowired
    private StudentService studentService;
    @RequestMapping({"/","index.html"})
    public String index(Model model){
        //获取焦点图
        ArticleCondition condition = new ArticleCondition();
        condition.setBanner(true);
        List<Article> banners = articleService.queryArticleByCondition(condition);
        model.addAttribute("banners",banners);
        //获取校园环境
        ActionResult<List<Environment>> listActionResult = envService.queryCurPageData(1, 5);
        model.addAttribute("environments",listActionResult.getData());
        //得到教师团队信息
        ActionResult<List<Teacher>> teacherResult = teacherService.queryCurPageData(1, 12);
        model.addAttribute("teachers",teacherResult.getData());
        //得到就业学生
        ActionResult<List<Student>> studentResult = studentService.queryStudent(1, 24);
        model.addAttribute("students",studentResult.getData());
        //获取推荐新闻
        condition = new ArticleCondition();
        condition.setRecommend(true);
        List<Article> recommends = articleService.queryArticleByCondition(condition);
        model.addAttribute("recommends",recommends);
        //获取活动图
        List<Article> articles = articleService.queryIndexActivity();
        model.addAttribute("articles",articles);
        //获取理工新闻
        ActionResult<List<Article>> campus = articleService.queryArticles("campus", 1, 8);
        model.addAttribute("campusList",campus.getData());

        return "index";
    }
}
